﻿using AutoMapper;
using MediatR;
using StoreIModels;
using StoreISet.Applicationes.Command;
using StoreRepositorys.Interface;

namespace StoreISet.Applicationes.CommandHandler
{
    /// <summary>
    /// 分类相册添加
    /// </summary>
    public class SystematicCreateCommandler : IRequestHandler<SystematicCreateCommand, int>
    {
        public ISystematicRepository _systematicRepository;
        public IMapper _mapper;
        public SystematicCreateCommandler(ISystematicRepository systematicRepository, IMapper mapper)
        {
            _systematicRepository = systematicRepository;
            _mapper = mapper;
        }

        public async Task<int> Handle(SystematicCreateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                SystematicModel model = _mapper.Map<SystematicModel>(request);
                return await _systematicRepository.Addasync(model);
            }
            catch (Exception)
            {

                throw;
            }
            
        }
    }
}
